import {Injectable, Type} from "@angular/core";
import {Hero} from "../models/hero";
import {Logger} from "./logger.service";
import {Crisis} from "../models/crisis";

const HEROES = [
  new Hero('Windstorm', 'Weather mastery'),
  new Hero('Mr. Nice', 'Killing them with kindness'),
  new Hero('Magneta', 'Manipulates metalic objects'),
  new Hero('Narco'),
  new Hero('Bombasto'),
  new Hero('Celeritas'),
  new Hero('RubberMan'),
  new Hero('Dynama'),
  new Hero('Dr IQ'),
  new Hero('Magma'),
  new Hero('Tornado')
];

const CRISES: Crisis[] = [
  new Crisis(1, 'Dragon Burning Cities'),
  new Crisis(2, 'Sky Rains Great White Sharks'),
  new Crisis(3, 'Giant Asteroid Heading For Earth'),
  new Crisis(4, 'Procrastinators Meeting Delayed Again'),
]

@Injectable()
export class BackendService {

  constructor(private logger: Logger) {
  }

  getAll(type: Type<any>): Promise<any[]> {
    if (type === Hero) {
      return Promise.resolve<Hero[]>(HEROES)
    }
    if (type === Crisis) {
      return Promise.resolve<Crisis[]>(CRISES)
    }
    let err = new Error('Cannot get object of this type')
    this.logger.error(err)
    throw err
  }
}
